<template>
  <div class="app-container">
    修改属性
    <el-form ref="user" :model="user" label-width="120px">
      <el-form-item label="玩家昵称">
        <label> {{ user.name }} </label>
      </el-form-item>
      <el-form-item label="uid">
        <label> {{ user._uid }} </label>
      </el-form-item>
      <el-form-item label="accountId">
        <label> {{ user.accountId }} </label>
      </el-form-item>
      <el-form-item label="星星">
        <label> {{ user.starSum }} </label>
      </el-form-item>
      <el-form-item label="钻石">
        <el-input v-model.number="user.diamon" type="number" style="width:300px" />
      </el-form-item>
      <el-form-item label="金币">
        <el-input v-model.number="user.gold" type="number" style="width:300px" />
      </el-form-item>
      <el-form-item label="体力">
        <el-input v-model.number="user.energy" type="number" style="width:300px" />
      </el-form-item>
      <el-form-item label="盾牌">
        <label> {{ user.shield }} </label>
      </el-form-item>
      <el-form-item label="当前关卡信息">
        <label> 第 {{ user.pos.lockBlockTid }} 关， 第 {{ user.pos.layerId }} 层</label>
      </el-form-item>
      <el-form-item label="最大关卡信息">
        <label> 第 {{ user.maxPos.lockBlockTid }} 关， 第 {{ user.maxPos.layerId }} 层 </label>
      </el-form-item>
      <el-form-item label="公会名称">
        <label>[{{ union.shortName }}]{{ union.name }}</label>
      </el-form-item>
      <el-form-item label="公会积分">
        <label>{{ user.unionScore }}</label>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">确认修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUserInfo, setUserInfo } from '@/api/gameuser'
import { getUnionInfo } from '@/api/union'

export default {
  data() {
    return {
      user: {
        _uid: '',
        name: '',
        gold: 0,
        accountId: '',
        energy: 0,
        starSum: 0,
        lastLoginTime: 0,
        maxPos: {
          layerId: 0,
          layerOpenGridNum: 0,
          lockBlockTid: 0
        },
        pos: {
          layerId: 0,
          layerOpenGridNum: 0,
          lockBlockTid: 0
        },
        shield: 0,
        slotLv: 0,
        unionScore: 0,
        unionId: ''
      },
      union: {
        uid: '',
        name: '',
        shortName: ''
      }
    }
  },
  created() {
    this.user.uid = this.$route.params && this.$route.params.uid
    this.fetchData()
  },
  methods: {
    fetchData() {
      getUserInfo(this.user.uid).then(response => {
        this.user = response.data.user
        this.user.starSum = this.user.star + this.user.starHero + this.user.starPet + this.user.starMap + this.user.starAchiev
        if (this.user.unionId !== '') {
          getUnionInfo(this.user.unionId).then(response => {
            this.union = response.data.union
          })
        }
      })
    },
    onSubmit() {
      setUserInfo(this.user).then(response => {
        this.$notify({
          title: '提示',
          message: '修改成功',
          type: 'success',
          duration: 2000
        })
      })
    },
    inputChange() { // 输入框值改变
      this.pageIndex = this.pageIndex.replace(/[^\d]/g, '')
    }
  }
}
</script>
